/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package learning.java.web.json;

import org.apache.http.client.fluent.Request;

import com.google.gson.Gson;

/**
 * 
 * @author Rayliu40k
 * @version $Id: GsonTest.java, v 0.1 Aug 22, 2021 3:14:23 PM Rayliu40k Exp $
 */
public class GsonTest {

    /**
     * 
     * @param args
     */
    public static void main(String[] args) throws Exception {
        String json = Request.Get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1")
            .execute().returnContent().asString();
        HPImage hpimage = new Gson().fromJson(json, HPImage.class);
        for (Image image : hpimage.getImages()) {
            java.net.URI uri = java.net.URI.create("https://www.bing.com" + image.getUrl());
            java.awt.Desktop dp = java.awt.Desktop.getDesktop();
            //判断系统桌面是否支持要执行的功能
            if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
                //获取系统默认浏览器打开链接
                dp.browse(uri);
            }
        }
    }

}
